<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/JSTLFunction.tld" prefix="lotofn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<title>用户管理</title>
<c:import url="/ctrl/header"></c:import>
<link href="/styles/datepicker.css" rel="stylesheet" />
<script>
	function checkForm() {
		var url = '/oem/userlist?';
		var name = $.trim($("#name").val());
		var begin = $.trim($("#begin").val());
		var end = $.trim($("#end").val());
		var status = $.trim($("#status").val());
		var dreg = /^(\d{1,4})(-|\/)(\d{1,2})(-|\/)(\d{1,2})$/;
		var params = new Array();
		var i = 0;
		if (name != "") {
			params[i] = "custName=" + name;
			i++;
		}
		if (status != "") {
			params[i] = "custStatus=" + status;
			i++;
		}
		if (begin.match(dreg) != null && end.match(dreg) != null
				&& new Date(begin) <= new Date(end)) {
			params[i] = "custBegin=" + begin;
			i++;
			params[i] = "custEnd=" + end;
			i++;
		}
		if (params.length == 0)
			alert("必须输入一项查询条件！");
		else
			location.href = url + params.join("&");
		return false;
	}
</script>
</head>
<body>
  <c:import url="/ctrl/top"></c:import>
  <div class="container">
    <div class="row-fluid">
      <c:import url="/ctrl/menu">
        <c:param name="pageId">
          <c:out value="${pageId}" />
        </c:param>
      </c:import>
      <!--/span-->
      <div class="span10">
        <h3 class="greybg">用户管理</h3>
        <div>
          <form method="post" action="" class="form-search">
            <label>会员名</label><input name="name" type="text" id="name"
              value="<c:out value="${custName}" />" /> <label>注册日期</label>
            <div class="input-append date"
              data-date="@DateTime.Now.AddMonths(-1).ToString('yyyy-MM-dd')"
              data-date-format="yyyy-mm-dd">
              <input name="begin" type="text" size="8" id="begin"
                data-date-format="yyyy-mm-dd"
                value="<c:out value="${custBegin}" />" readonly /> <span
                class="add-on"><i class="icon-calendar"></i></span>
            </div>
            &nbsp;-&nbsp;
            <div class="input-append date"
              data-date="@DateTime.Now.AddMonths(-1).ToString('yyyy-MM-dd')"
              data-date-format="yyyy-mm-dd">
              <input name="end" type="text" size="8" id="end"
                data-date-format="yyyy-mm-dd"
                value="<c:out value="${custEnd}" />" readonly /> <span
                class="add-on"><i class="icon-calendar"></i></span>
            </div>
            <label>用户状态</label><select name="status" id="status">
              <option value=""></option>
              <c:forEach var="status" items="${custStatusList}">
                <option value="<c:out value="${status.index}" />"
                  <c:if test="${custStatus==status.index}">selected="selected"</c:if>><c:out
                    value="${status.name}" /></option>
              </c:forEach>
            </select> &nbsp;&nbsp; <input type="submit" name="btnQuery"
              value="查询" id="btnQuery" onclick="return checkForm();"
              class="button btn-big btn-orange" />
          </form>
        </div>
        <table
          class="table table-bordered table-striped responsive-utilities table-hover">
          <thead>
            <tr>
              <th>用户名</th>
              <th>用户等级</th>
              <th>等级折扣</th>
              <th>账户余额</th>
              <th>注册时间</th>
              <th>最后登录时间</th>
              <th>状态</th>
              <th>是否内部用户</th>
            </tr>
          </thead>
          <tbody>
            <c:choose>
              <c:when test="${pager.rowCount>0}">
                <c:forEach var="cust" items="${custList}">
                  <tr>
                    <td><a
                      href="/oem/userdetail?id=<c:out value="${cust.custId}" />"
                      target="_blank"><c:out
                          value="${cust.custName}" /></a></td>
                    <td><c:out value="${cust.levelName}" /></td>
                    <td><fmt:formatNumber var="levelDiscount"
                        type="number" pattern="0.00%"
                        value="${cust.levelDiscount}" /> <c:out
                        value="${levelDiscount}" /></td>
                    <td><fmt:formatNumber var="custUsefulFee"
                        type="currency" pattern="￥0.00"
                        value="${cust.custUsefulFee}" /> <c:out
                        value="${custUsefulFee}" /></td>
                    <td><fmt:formatDate var="custCreatedOn"
                        pattern="yyyy-MM-dd HH:mm"
                        value="${cust.custCreatedOn}" /> <c:out
                        value="${custCreatedOn}" /></td>
                    <td><fmt:formatDate var="custLastActivedOn"
                        pattern="yyyy-MM-dd HH:mm"
                        value="${cust.custLastActivedOn}" /> <c:out
                        value="${custLastActivedOn}" /></td>
                    <td><c:out
                        value="${lotofn:getCustStatusDesc(cust.custStatus)}" /></td>
                    <td><c:out
                        value="${lotofn:getCustIsInner(cust.custUserFlg)}" /></td>
                  </tr>
                </c:forEach>
              </c:when>
              <c:otherwise>
                <tr>
                  <td colspan="6" style="text-align: center;">没有相关信息</td>
                </tr>
              </c:otherwise>
            </c:choose>

          </tbody>
        </table>

        <c:import url="/ctrl/pager">
          <c:param name="index" value="${pager.index}" />
          <c:param name="rowcount" value="${pager.rowCount}" />
          <c:param name="params" value="${pager.params}" />
          <c:param name="pagesize" value="${pager.pageSize}" />
          <c:param name="pagename" value="/oem/userlist" />
        </c:import>

      </div>
    </div>
    <hr />
    <c:import url="/ctrl/bottom"></c:import>
  </div>

  <c:import url="/ctrl/footer"></c:import>
  <script src="/scripts/bootstrap-datepicker.js"></script>
</body>
</html>